﻿#include "AbstractSpinBoxPropertyEditEntry.h"
#include <QAbstractSpinBox>

#include "BooleanEditEntry.h"
#include "EnumEditEntry.h"
#include "UiTextEditEntry.h"
#include "AlignmentEditEntry.h"

#include "ObjectPropertyEditEntryFactory.h"
REGISTER_PROPERTY_EDIT_ENTRY(AbstractSpinBox)

struct AbstractSpinBoxPropertyEditEntry::AbstractSpinBoxPropertyEditEntryPrivate {
    QPointer<QAbstractSpinBox> object;

    QPointer<BooleanEditEntry> entryWrapping;
    QPointer<BooleanEditEntry> entryFrame;
    QPointer<AlignmentEditEntry> entryAlignment;
    QPointer<BooleanEditEntry> entryReadOnly;
    QPointer<EnumEditEntry> entryButtonSymbols;
    QPointer<UiTextEditEntry> entrySpecialValueText;
    QPointer<BooleanEditEntry> entryAccelerated;
    QPointer<EnumEditEntry> entryCorrectionMode;
    QPointer<BooleanEditEntry> entryKeybrdTracking;
    QPointer<BooleanEditEntry> entryShowGroupSeparator;
};

AbstractSpinBoxPropertyEditEntry::~AbstractSpinBoxPropertyEditEntry() { }

AbstractSpinBoxPropertyEditEntry::AbstractSpinBoxPropertyEditEntry(QWidget *parent) : PropertyEditEntry{parent} {
    p.reset(new AbstractSpinBoxPropertyEditEntryPrivate);
    initUi();
    retranslateUi();
}

void AbstractSpinBoxPropertyEditEntry::setObject(void *object) {
    p->object = static_cast<QAbstractSpinBox*>(object);
}

void AbstractSpinBoxPropertyEditEntry::onTick() {
    if(!p->object || !isVisible()) {
        return ;
    }

    p->entryWrapping->setValue(p->object->wrapping());
    p->entryFrame->setValue(p->object->hasFrame());
    p->entryAlignment->setValue(p->object->alignment());
    p->entryReadOnly->setValue(p->object->isReadOnly());
    p->entryButtonSymbols->setValue(p->object->buttonSymbols());
    p->entrySpecialValueText->setValue(p->object->specialValueText());
    p->entryAccelerated->setValue(p->object->isAccelerated());
    p->entryCorrectionMode->setValue(p->object->correctionMode());
    p->entryKeybrdTracking->setValue(p->object->keyboardTracking());
    p->entryShowGroupSeparator->setValue(p->object->isGroupSeparatorShown());
}

void AbstractSpinBoxPropertyEditEntry::initUi() {
    p->entryWrapping = new BooleanEditEntry;
    appendChildEntry(p->entryWrapping);

    p->entryFrame = new BooleanEditEntry;
    appendChildEntry(p->entryFrame);

    p->entryAlignment = new AlignmentEditEntry;
    appendChildEntry(p->entryAlignment);

    p->entryReadOnly = new BooleanEditEntry;
    appendChildEntry(p->entryReadOnly);

    p->entryButtonSymbols = new EnumEditEntry;
    p->entryButtonSymbols->setMetaEnum(QMetaEnum::fromType<QAbstractSpinBox::ButtonSymbols>());
    appendChildEntry(p->entryButtonSymbols);

    p->entrySpecialValueText = new UiTextEditEntry;
    appendChildEntry(p->entrySpecialValueText);

    p->entryAccelerated = new BooleanEditEntry;
    appendChildEntry(p->entryAccelerated);

    p->entryCorrectionMode = new EnumEditEntry;
    p->entryCorrectionMode->setMetaEnum(QMetaEnum::fromType<QAbstractSpinBox::CorrectionMode>());
    appendChildEntry(p->entryCorrectionMode);

    p->entryKeybrdTracking = new BooleanEditEntry;
    appendChildEntry(p->entryKeybrdTracking);

    p->entryShowGroupSeparator = new BooleanEditEntry;
    appendChildEntry(p->entryShowGroupSeparator);
}

void AbstractSpinBoxPropertyEditEntry::retranslateUi() {
    setTitle(tr("QAbstractSpinBox"));
    p->entryWrapping->setTitle(tr("wrapping"));
    p->entryFrame->setTitle(tr("frame"));
    p->entryAlignment->setTitle(tr("alignment"));
    p->entryReadOnly->setTitle(tr("readOnly"));
    p->entryButtonSymbols->setTitle(tr("buttonSymbols"));
    p->entrySpecialValueText->setTitle(tr("specialValueText"));
    p->entryAccelerated->setTitle(tr("accelerated"));
    p->entryCorrectionMode->setTitle(tr("correctionMode"));
    p->entryKeybrdTracking->setTitle(tr("keyboardTracking"));
    p->entryShowGroupSeparator->setTitle(tr("showGroupIndicator"));
}
